const path = require('path')
const Router = require('@koa/router');
const koaStatic = require('koa-static');
const user = require('../model/mysql/user')
const db = require('../config/mysql')

const router = new Router({ 
  prefix: '/global' 
});

router.get('/users', async (ctx, next) => {
  const data = await db.query("select *, COALESCE(idCard, 0) as idCard, coalesce(age, 0) as age from user where name regexp '^d'")
  // const data = await user.findAll();
  ctx.body = {
    data: data[0],
    code: 1000
  }
})

router.get('/setUser', async (ctx, next) => {
  await user.create({
    id: 0,
    name: "士大夫",
    password: "14457845",
    age: 36,
    sex: 2,
    idCard: null,
    createTime: Date.now()
  })
  ctx.body = {
    code: 1000
  }
})

module.exports = router;